
import java.util.Random;
import org.murillo.chufa.Cache;
import javax.xml.stream.XMLStreamException;
import org.murillo.utils.debug.tostring.ReflectToString;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Administrador
 */
public class Test {

    public static void main(String[] args) throws InterruptedException, XMLStreamException {
        long t = System.currentTimeMillis();
        Cache c = new Cache(20, 2, false);
        Random rdm = new Random(0);
        for (int i = 0; i < 10000; i++) {
            double r = rdm.nextDouble();
            Object k;
            Object v;
            if (r < 0.5) {
                k = (int) (0.5 + 2 * r * 10);
            } else {
                k = (int) (10.5 + 2 * (r - 0.5) * 90);
            }
            v = c.get(k);
            if (v == null) {
                c.put(k, new Dummy(k), 1);
            } else {
                //System.out.println("GOTCHA! "+k);
            }
        }
        System.out.println(System.currentTimeMillis() - t);
        System.out.println(c.getHitRatio());
        System.out.println(new ReflectToString().setMaxArrayItems(-1).setNavigateReferences(true).toString(c.hardlist));
    }

}

class Dummy {

    public Dummy(Object k) throws InterruptedException {
//        System.out.println("NUEVO: "+k);
        //Thread.sleep(100L);
    }
}
